package com.gnerv.pabu.plugin.config;

import com.gnerv.pabu.plugin.entity.TemplateGroup;
import com.gnerv.pabu.plugin.utils.TemplateGroupUtils;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;

@Slf4j
@Data
@State(name = "PabuAnnotationSettings", storages = @Storage("pabu-annotation-settings.xml"))
public class AnnotationSettings implements PersistentStateComponent<AnnotationSettings> {

    public static final String GROUP_NAME = "Annotation";
    public static final String GROUP_PATH = "/template/Annotation/";
    public static final String[] TEMPLATES = new String[]{"annotation.class"};
    public static final String TYPE = ".vm";

    private TemplateGroup templateGroup;

    private String author;

    public AnnotationSettings(){
        try {
            templateGroup = TemplateGroupUtils.loadTemplate(GROUP_NAME, GROUP_PATH, TEMPLATES, TYPE);
        } catch (IOException e) {
            log.info("加载 MybatisPlus 模板失败", e);
        }
    }

    @Nullable
    @Override
    public AnnotationSettings getState() {
        return null;
    }

    @Override
    public void loadState(@NotNull AnnotationSettings annotationSettings) {
        XmlSerializerUtil.copyBean(annotationSettings, this);
    }
}
